<?php
namespace addon\cms\validate;
use app\common\validate\ValidateBase;
class Category extends ValidateBase
{
    // 验证规则
    protected $rule = [
        'title'                 => 'require',
        'channel_id'            => 'require|checkChannel'
    ];

    // 验证提示
    protected $message = [
        'title.require'         => '分类标题不能为空',
        'channel_id.require'    => '内容模型必须',
    ];

    // 应用场景
    protected $scene = [
        'add'  =>  ['title','channel_id'],
    ];
    protected function checkChannel($value){
        $channel=config("config.cms_channel");
        if(empty($channel)){
            return "配置文件出错";
        }
        $keys = array_keys($channel);
        if(!in_array($value, $keys)){
            return "非法的数据模型";
        }
        return true;
    }
}